VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "Detail"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
'/******************************************************************/
'/*                                                                */
'/*                      TurboCAD for Windows                      */
'/*                   Copyright (c) 1993 - 2001                    */
'/*             International Microcomputer Software, Inc.         */
'/*                            (IMSI)                              */
'/*                      All rights reserved.                      */
'/*                                                                */
'/******************************************************************/

'DBAPI constants
Const gkGraphic = 11
Const gkArc = 2
Const gkText = 6
Const gfCosmetic = 128&
                                                                                                                                                                                             
'Useful math constants
Const Pi# = 3.14159265

'Real variant types!
Const typeEmpty = 0
Const typeInteger = 2
Const typeLong = 3
Const typeSingle = 4
Const typeDouble = 5
Const typeCurrency = 6
Const typeDate = 7
Const typeString = 8
Const typeObject = 9
Const typeBoolean = 11
Const typeVariant = 12
Const typeIntegerEnum = typeInteger + 100
Const typeLongEnum = typeLong + 100
Const typeStringEnum = typeString + 100

'Stock property pages
Const ppStockPen = 1
Const ppStockBrush = 2
Const ppStockText = 4
Const ppStockInsert = 8
Const ppStockViewport = 16
Const ppStockAuto = 32

'Property Ids
Const idNutType = 1
Const idDiameter = 2
Const idLength = 3
Const idView = 4
Const idLengthThread = 5

'Property enums


'Number of properties, pages, wizards
Const NUM_PROPERTIES = 5
Const NUM_PAGES = 1
Const NUM_WIZARDS = 0
Private PColor As Long
Private BColor As Long


Private Sub Class_Initialize()
    'Initialize class variables
End Sub

'Returns the user-visible description of this RegenMethod
Public Property Get Description() As String
    Description = "Nut"
End Property

'Returns the persistent class id for this RegenMethod's property section
Public Property Get ClassID() As String
    ClassID = "{FDB6F1C3-9631-11d1-A40A-0000B465872B}"

End Property

'Retrieve types and names
Public Function GetPropertyInfo(Names As Variant, Types As Variant, _
    IDs As Variant, Defaults As Variant) As Long
    ReDim Names(NUM_PROPERTIES), Types(NUM_PROPERTIES), _
        IDs(NUM_PROPERTIES), Defaults(NUM_PROPERTIES)
    Names(0) = "NutType"
    Types(0) = typeString
    IDs(0) = idNutType
    Defaults(0) = "HexNut"
        
    Names(1) = "DiameterN"
    Types(1) = typeDouble
    IDs(1) = idDiameter
    Defaults(1) = 1#

    Names(2) = "LengthN"
    Types(2) = typeDouble
    IDs(2) = idLength
    Defaults(2) = 3#
    
    Names(3) = "NutView"
    Types(3) = typeString
    IDs(3) = idView
    Defaults(3) = "Front"
   
    Names(4) = "LengthThreadN"
    Types(4) = typeDouble
    IDs(4) = idLengthThread
    Defaults(4) = 0#
   
   GetPropertyInfo = NUM_PROPERTIES
End Function

'Get the number of property pages supporting this RegenMethod
Public Function GetPageInfo(ByVal AGraphic As Object, StockPages As Long, _
    Names As Variant) As Long
    ReDim Names(NUM_PAGES)

    'Need the form
'    Load frmSample
'    Names(0) = frmSample.Caption
'    Unload frmSample
    Names(0) = LoadResString(101)
    StockPages = ppStockBrush + ppStockPen + ppStockAuto
    GetPageInfo = NUM_PAGES
End Function

Public Function GetWizardInfo(Names As Variant) As Long
    ReDim Names(NUM_WIZARDS)
    GetWizardInfo = NUM_WIZARDS
End Function

'Enumerate the names and values of a specified property
Public Function GetEnumNames(ByVal PropID As Long, Names As Variant, Values As Variant) As Long

End Function

Public Function PageControls(ByVal ThisRegenMethod As Object, ByVal Graphic As Object, ByVal PageNumber As Long, ByVal SaveProperties As Boolean) As Boolean
        'Set up error function
        On Error GoTo Failed
        Dim i%
        Dim Diameter#, Length#, LThread#
        If SaveProperties Then
            'OK button on property page was clicked
            'Form is still loaded
            With frmSample
                'Need On Error statement for the case where you have
                'RRect Turbo Shape and ahother "shape" selected
                On Error Resume Next
                'When the property page is closed, transfer the numeric
                'Diameter value from the TextBox to the Graphic
                'Get the value as a double-precision number
                TypeN = .List1.Text
                ViewN = .List2.Text
                Diameter# = CDbl(.txtdd.Text)
                LThread# = CDbl(.txtLenThread.Text)
                
                'Make sure it's between 0 and 100
                If Diameter# < 0# Then Diameter# = 1#
                If Diameter# > 3# Then Diameter# = 3#
                
                'Set the roundness property value in the Graphic
                Graphic.Properties("DiameterN") = Diameter#
                Graphic.Properties("NutType") = TypeN
                Graphic.Properties("NutView") = ViewN
                Graphic.Properties("LengthThreadN") = LThread
                
            End With
        Else
            'Property page is about to be opened
            'Make sure the form is loaded
            Load frmSample
            With frmSample
            
                'If more than one RRect is selected and they do not
                'have the same properties, don't set up this field
                On Error GoTo NoRType

                'When the property page is opening, transfer the numeric
                'roundness value from the Graphic to the TextBox
                'Get the roundness property value from the Graphic
                Diameter# = Graphic.Properties("DiameterN")
                TypeN = Graphic.Properties("NutType")
                ViewN = Graphic.Properties("NutView")
                LThread = Graphic.Properties("LengthThreadN")
            'Set the TextBox control's text
                .txtdd.Text = Diameter#
                .List1.Text = TypeN
                .List2.Text = ViewN
                .txtLenThread.Text = LThread
NoRType:
            End With
        End If

        PageControls = True
        Exit Function

Failed:
        'For debugging purposes, report that an error occurred
        If Err.Number <> 0 Then
            MsgBox "Error in PageControls: " & Err.Description
        End If

        'Return false if an error occurred
        PageControls = False
End Function

Public Function PageDone(ByVal ThisRegenMethod As Object, Optional PageNumber As Variant)
        'Done with form
        Unload frmSample
End Function

Public Function PropertyPages(ByVal ThisRegenMethod As Object, Optional PageNumber As Variant) As Boolean
    With frmSample
        .Show vbModal
        PropertyPages = Not .DialogCanceled
    End With
End Function

Public Function Wizard(ByVal ThisRegenMethod As Object, Optional WizardNumber As Variant) As Boolean
    Wizard = False
End Function

'Called when vertex has been moved, or other geometry change
Public Function OnGeometryChanged(ByVal Graphic As Object, ByVal GeomID As Long, paramOld As Variant, paramNew As Variant)
    'Do nothing
    'Regen Graphic
End Function

'Called when vertex is moved, or other geometry change
Public Function OnGeometryChanging(ByVal Graphic As Object, ByVal GeomID As Long, paramOld As Variant, paramNew As Variant) As Boolean
    'OK to continue with change
    OnGeometryChanging = True
End Function

Public Function OnNewGraphic(ByVal grfThis As Object, ByVal boolCopy As Boolean) As Boolean
    If boolCopy Then
        'Vertices are already added for us...
        OnNewGraphic = True
        Exit Function
    End If

    On Error GoTo Failed
    'New Graphic being created
    'X, Y, Z, PenDown, Selectable, Snappable, Editable, Linkable
    'First Vertex is "first point of axis"
    grfThis.Vertices.Add 0#, 0, 0#, False, True, True, True, True, False
    
    'Second Vertex is "Second point of axis"
    
    grfThis.Vertices.Add 3#, 0, 0#, False, True, True, True, True, False
    grfThis.Properties("PenColor") = RGB(0, 0, 0)
    grfThis.Properties("BrushColor") = RGB(255, 255, 255)
    
    OnNewGraphic = True
    Exit Function

Failed:
    'Return false on failure
    OnNewGraphic = False
End Function

'Function called whenever a copy of a graphic is being made
Public Function OnCopyGraphic(ByVal grfCopy As Object, ByVal grfSource As Object) As Boolean
    'Return false on failure
    OnCopyGraphic = True
End Function

'Notification function called after graphic property is saved
Public Function OnPropertyChanged(ByVal Graphic As Object, ByVal PropID As Long, _
        ValueOld As Variant, ValueNew As Variant)
    'Do nothing
End Function

'Notification function called when graphic property is saved
Public Function OnPropertyChanging(ByVal Graphic As Object, ByVal PropID As Long, _
        ValueOld As Variant, ValueNew As Variant) As Boolean
    'OK to proceed
    OnPropertyChanging = True
End Function

'Notification function called when graphic property is retrieved
Public Function OnPropertyGet(ByVal Graphic As Object, ByVal PropID As Long)
    'Do nothing
End Function

'Called when we need to update our object
Public Function Regen(ByVal grfThis As Object)
        'Setup error handler
        On Error GoTo Failed

        'Set up lock (prevent recursion)
        Dim LockCount&
        LockCount& = grfThis.RegenLock
        PColor = grfThis.Properties("PenColor")
''AALB problem with load old files
' AALB try to fix bug with reading files from TC v6.5 (problem is that some sdk regens
' has Type = 7(Group, must be GRAPHIc (11))
On Error Resume Next
Err.Clear
        BColor = grfThis.Properties("BrushColor")
        If Err.Number <> 0 Then
            BColor = RGB(255, 255, 255)
            Err.Clear
        End If
        
        
        'Setup error handler (make sure lock is removed)
        On Error GoTo FailedLock
        If LockCount& = 0 Then
            'Delete any previous cosmetic children
            grfThis.Graphics.Clear gfCosmetic

            TypeN = grfThis.Properties("NutType")
            ViewN = grfThis.Properties("NutView")

            Dim dd#
                dd = grfThis.Properties("DiameterN")
                
            Dim LThread#
                LThread = grfThis.Properties("LengthThreadN")
Dim X00#, Y00#, X01#, Y01#
            With grfThis.Vertices
                X00 = .Item(0).X
                Y00 = .Item(0).Y
                X01 = .Item(1).X
                Y01 = .Item(1).Y
                If Abs(X00 - X01) < 0.001 And Abs(Y00 - Y01) < 0.001 Then
                    .Item(1).X = X00 + 1#
                    .Item(1).Y = Y00
                End If
            End With
'##########################################################
            If TypeN = "HexNut" Then
                Call HexNut(grfThis, dd, LThread)
            End If
                   
            If TypeN = "HexFlangeNut" Then
                Call HexFlangeNut(grfThis, dd, LThread)
            End If
            
            If TypeN = "HexSlottedNut" Then
                Call HexSlottedNut(grfThis, dd, LThread)
            End If
            
            If TypeN = "LowCrownNut" Then
                Call LowCrownNut(grfThis, dd, LThread)
            End If

            If TypeN = "SquareNut" Then
                Call SquareNut(grfThis, dd, LThread)
            End If

            'Add visible child Graphics
        End If

        grfThis.RegenUnlock
        Exit Function

FailedLock:
        'Remove lock
        grfThis.RegenUnlock

Failed:
End Function

Public Function Draw(ByVal grfThis As Object, ByVal view As Object, Optional mat As Variant) As Boolean
    'Return True if we did the redraw (no further processing necessary, no children will be drawn).
    'Since this is just a test, we return False to let TurboCAD do the drawing operation.
    Draw = False
End Function
Private Function Angle(sinb As Double, cosb As Double) As Double

        If Abs(cosb) < 0.0001 Then
            If sinb > 0 Then
                Angle = Pi / 2
            Else
                Angle = 3 * Pi / 2
            End If
        Else
            If sinb >= 0 And cosb > 0 Then Angle = Atn(sinb / cosb)
            If sinb >= 0 And cosb < 0 Then Angle = Pi + Atn(sinb / cosb)
            If sinb < 0 And cosb < 0 Then Angle = Pi + Atn(sinb / cosb)
            If sinb < 0 And cosb > 0 Then Angle = 2 * Pi + Atn(sinb / cosb)
        End If
End Function


Private Sub HexNut(Gr As Graphic, dd As Double, LThread As Double)
Dim D#, H#, S#, K#, del#
        D = 1.84 * dd
        H = 1# * dd
        S = D * Cos(Pi / 6)
        K = D / 2 * (1 - Cos(Pi / 6)) * Tan(Pi / 6)
        del = 0.15 * dd
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dim Salp#, Calp#, L#
Dim X00#, Y00#, X01#, Y01#
        With Gr.Vertices
            X00 = .Item(0).X
            Y00 = .Item(0).Y
            X01 = .Item(1).X
            Y01 = .Item(1).Y
            L = Sqr((X01 - X00) * (X01 - X00) + (Y01 - Y00) * (Y01 - Y00))
            Salp = (Y01 - Y00) / L
            Calp = (X01 - X00) / L
        End With
        If Abs(H - L) > 0.0001 Then
            X01 = X00 + H * Calp
            Y01 = Y00 + H * Salp
            With Gr.Vertices
                .Item(1).X = X01
                .Item(1).Y = Y01
                L = H
            End With
        End If
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Dim x0(26)
Dim y0(26)
Dim X(26)
Dim Y(26)
       
       x0(1) = 0#
       y0(1) = S / 2#
       
       x0(2) = x0(1)
       y0(2) = -y0(1)
       
       x0(3) = K
       y0(3) = D / 2#
       
       x0(4) = x0(3)
       y0(4) = -y0(3)
       
       x0(5) = H - K
       y0(5) = D / 2
       
       x0(6) = x0(5)
       y0(6) = -y0(5)
              
       x0(7) = H
       y0(7) = S / 2#
       
       x0(8) = x0(7)
       y0(8) = -y0(7)
       
       x0(9) = x0(3)
       y0(9) = D / 4
       
       x0(10) = x0(9)
       y0(10) = -y0(9)
       
       x0(11) = x0(5)
       y0(11) = D / 4#
       
       x0(12) = x0(11)
       y0(12) = -y0(11)
       
       x0(13) = 0#
       y0(13) = 3 * D / 8
       
       x0(14) = x0(13)
       y0(14) = -y0(13)
       
       x0(15) = H
       y0(15) = 3 * D / 8
       
       x0(16) = x0(15)
       y0(16) = -y0(15)
       
       x0(17) = 0
       y0(17) = 0
       
       x0(18) = H
       y0(18) = 0#
       
' Thread
       x0(19) = H
       y0(19) = dd / 2
       
       x0(20) = x0(19)
       y0(20) = -y0(19)
       
       x0(21) = H + LThread - del
       y0(21) = dd / 2
       
       x0(22) = x0(21)
       y0(22) = -y0(21)
       
       x0(23) = H + LThread
       y0(23) = dd / 2 - del
       
       x0(24) = x0(23)
       y0(24) = -y0(23)
       
       x0(25) = H
       y0(25) = dd / 2 - del
       
       x0(26) = x0(25)
       y0(26) = -y0(25)
       
Dim i%
       For i = 1 To 26
          X(i) = X00 + x0(i) * Calp - y0(i) * Salp
          Y(i) = Y00 + x0(i) * Salp + y0(i) * Calp
       Next i
Dim GrChild As Graphic
            'Add child Graphics
        If ViewN = "Front" Then
            If LThread > 0.01 * dd Then
                Set GrChild = Gr.Graphics.Add(gkGraphic)
                          GrChild.Cosmetic = True
                With GrChild.Vertices
                    .Add X(19), Y(19), 0, True, True, False, False, False, False
                    .Add X(21), Y(21), 0, True, True, False, False, False, False
                    .Add X(23), Y(23), 0, True, True, False, False, False, False
                    .Add X(24), Y(24), 0, True, True, False, False, False, False
                    .Add X(22), Y(22), 0, True, True, False, False, False, False
                    .Add X(20), Y(20), 0, True, True, False, False, False, False
                    .Add X(19), Y(19), 0, True, True, False, False, False, False
                End With
                GrChild.Closed = True
                GrChild.Properties("PenWidth") = 0.02
                GrChild.Properties("PenColor") = PColor
                GrChild.Properties("BrushStyle") = "Solid"
                GrChild.Properties("BrushColor") = BColor
                Set GrChild = Gr.Graphics.Add(gkGraphic)
                          GrChild.Cosmetic = True
                With GrChild.Vertices
                    .Add X(19), Y(19), 0, True, True, False, False, False, False
                    .Add X(20), Y(20), 0, True, True, False, False, False, False
                    .Add X(21), Y(21), 0, False, True, False, False, False, False
                    .Add X(22), Y(22), 0, True, True, False, False, False, False
                End With
                GrChild.Properties("PenWidth") = 0.02
                GrChild.Properties("PenColor") = PColor
                Set GrChild = Gr.Graphics.Add(gkGraphic)
                          GrChild.Cosmetic = True
                With GrChild.Vertices
                    .Add X(25), Y(25), 0, True, True, False, False, False, False
                    .Add X(23), Y(23), 0, True, True, False, False, False, False
                    .Add X(26), Y(26), 0, False, True, False, False, False, False
                    .Add X(24), Y(24), 0, True, True, False, False, False, False
                End With
                GrChild.Properties("PenColor") = PColor
            End If
            Set GrChild = Gr.Graphics.Add(gkGraphic)
                    GrChild.Cosmetic = True
            With GrChild.Vertices
                .Add X(1), Y(1), 0, True, True, False, False, False, False
                .Add X(3), Y(3), 0, True, True, False, False, False, False
                .Add X(5), Y(5), 0, True, True, False, False, False, False
                .Add X(7), Y(7), 0, True, True, False, False, False, False
                .Add X(8), Y(8), 0, True, True, False, False, False, False
                .Add X(6), Y(6), 0, True, True, False, False, False, False
                .Add X(4), Y(4), 0, True, True, False, False, False, False
                .Add X(2), Y(2), 0, True, True, False, False, False, False
                .Add X(1), Y(1), 0, True, True, False, False, False, False
            End With
            GrChild.Closed = True
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            GrChild.Properties("BrushStyle") = "Solid"
            GrChild.Properties("BrushColor") = BColor
             Set GrChild = Gr.Graphics.Add(gkGraphic)
                       GrChild.Cosmetic = True
             With GrChild.Vertices
                 .Add X(9), Y(9), 0, True, True, False, False, False, False
                 .Add X(11), Y(11), 0, True, True, False, False, False, False
                 .Add X(10), Y(10), 0, False, True, False, False, False, False
                 .Add X(12), Y(12), 0, True, True, False, False, False, False
             End With
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            '14
            Set GrChild = Gr.Graphics.AddArcTriplePoint(X(3), Y(3), 0#, X(13), Y(13), 0#, X(9), Y(9), 0#)
                       GrChild.Cosmetic = True
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            '15
            Set GrChild = Gr.Graphics.AddArcTriplePoint(X(9), Y(9), 0#, X(17), Y(17), 0#, X(10), Y(10), 0#)
                       GrChild.Cosmetic = True
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            '16
            Set GrChild = Gr.Graphics.AddArcTriplePoint(X(10), Y(10), 0#, X(14), Y(14), 0#, X(4), Y(4), 0#)
                       GrChild.Cosmetic = True
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
                       
            '14
            Set GrChild = Gr.Graphics.AddArcTriplePoint(X(5), Y(5), 0#, X(15), Y(15), 0#, X(11), Y(11), 0#)
                       GrChild.Cosmetic = True
             GrChild.Properties("PenWidth") = 0.02
             GrChild.Properties("PenColor") = PColor
           '15
            Set GrChild = Gr.Graphics.AddArcTriplePoint(X(11), Y(11), 0#, X(18), Y(18), 0#, X(12), Y(12), 0#)
                       GrChild.Cosmetic = True
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            '16
            Set GrChild = Gr.Graphics.AddArcTriplePoint(X(12), Y(12), 0#, X(16), Y(16), 0#, X(6), Y(6), 0#)
                       GrChild.Cosmetic = True
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
        End If
'-------------------------------------------------------------
        If ViewN = "Top" Then
' View Top
            Set GrChild = Gr.Graphics.Add(gkGraphic)
                      GrChild.Cosmetic = True
            With GrChild.Vertices
                For i = 0 To 6
                    x0(i) = D / 2 * Cos(Pi / 3 * i)
                    y0(i) = D / 2 * Sin(Pi / 3 * i)
                    X(i) = X00 + x0(i) * Calp - y0(i) * Salp
                    Y(i) = Y00 + x0(i) * Salp + y0(i) * Calp
                   .Add X(i), Y(i), 0, True, True, False, False, False, False
                Next i
            End With
             GrChild.Closed = True
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
             GrChild.Properties("BrushStyle") = "Solid"
             GrChild.Properties("BrushColor") = BColor
            Set GrChild = Gr.Graphics.AddCircleCenterAndPoint(X00, Y00, 0, X00 + D / 2 * Sin(Pi / 3), Y00, 0)
                      GrChild.Cosmetic = True
             GrChild.Properties("PenWidth") = 0.02
             GrChild.Properties("PenColor") = PColor
            Set GrChild = Gr.Graphics.AddCircleCenterAndPoint(X00, Y00, 0, X00 + dd / 2, Y00, 0)
                      GrChild.Cosmetic = True
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            Set GrChild = Gr.Graphics.AddCircleCenterAndPoint(X00, Y00, 0, X00 + dd / 2 - del, Y00, 0)
                      GrChild.Cosmetic = True
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            x0(7) = D / 2
            y0(7) = 0
            X(7) = X00 + x0(7) * Calp - y0(7) * Salp
            Y(7) = Y00 + x0(7) * Salp + y0(7) * Calp
            
           With Gr.Vertices
                .Item(1).X = X(7)
                .Item(1).Y = Y(7)
            End With
        End If
End Sub



Private Sub LowCrownNut(Gr As Graphic, dd As Double, LThread As Double)
Dim D#, H#, S#, K#
        D = 1.63 * dd
        H = 0.72 * dd
        S = D * Cos(Pi / 6)
        K = D / 2 * (1 - Cos(Pi / 6)) * Tan(Pi / 6)
Dim Q#
        Q = 1.55 * dd '1.55
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dim Salp#, Calp#, L#
Dim X00#, Y00#, X01#, Y01#
        With Gr.Vertices
            X00 = .Item(0).X
            Y00 = .Item(0).Y
            X01 = .Item(1).X
            Y01 = .Item(1).Y
            L = Sqr((X01 - X00) * (X01 - X00) + (Y01 - Y00) * (Y01 - Y00))
            Salp = (Y01 - Y00) / L
            Calp = (X01 - X00) / L
        End With
        If Abs(H - L) > 0.0001 Then
            X01 = X00 + H * Calp
            Y01 = Y00 + H * Salp
            With Gr.Vertices
                .Item(1).X = X01
                .Item(1).Y = Y01
                L = H
            End With
        End If
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Dim x0(19)
Dim y0(19)
Dim X(19)
Dim Y(19)
       
       x0(1) = 0#
       y0(1) = S / 2#
       
       x0(2) = x0(1)
       y0(2) = -y0(1)
       
       x0(3) = K
       y0(3) = D / 2#
       
       x0(4) = x0(3)
       y0(4) = -y0(3)
       
       x0(5) = H - K
       y0(5) = D / 2
       
       x0(6) = x0(5)
       y0(6) = -y0(5)
              
       x0(7) = H
       y0(7) = S / 2#
       
       x0(8) = x0(7)
       y0(8) = -y0(7)
       
       x0(9) = x0(3)
       y0(9) = D / 4
       
       x0(10) = x0(9)
       y0(10) = -y0(9)
       
       x0(11) = x0(5)
       y0(11) = D / 4#
       
       x0(12) = x0(11)
       y0(12) = -y0(11)
       
       x0(13) = 0#
       y0(13) = 3 * D / 8
       
       x0(14) = x0(13)
       y0(14) = -y0(13)
       
       x0(15) = H
       y0(15) = 3 * D / 8
       
       x0(16) = x0(15)
       y0(16) = -y0(15)
       
       x0(17) = 0
       y0(17) = 0
       
       x0(18) = H
       y0(18) = 0#
       
       x0(19) = Q
       y0(19) = 0#
       
       
Dim i%
       For i = 1 To 19
          X(i) = X00 + x0(i) * Calp - y0(i) * Salp
          Y(i) = Y00 + x0(i) * Salp + y0(i) * Calp
       Next i
Dim GrChild As Graphic
            'Add child Graphics
        If ViewN = "Front" Then
            Set GrChild = Gr.Graphics.Add(gkGraphic)
                      GrChild.Cosmetic = True
            With GrChild.Vertices
                .Add X(1), Y(1), 0, True, True, False, False, False, False
                .Add X(3), Y(3), 0, True, True, False, False, False, False
                .Add X(5), Y(5), 0, True, True, False, False, False, False
                .Add X(7), Y(7), 0, True, True, False, False, False, False
                .Add X(8), Y(8), 0, True, True, False, False, False, False
                .Add X(6), Y(6), 0, True, True, False, False, False, False
                .Add X(4), Y(4), 0, True, True, False, False, False, False
                .Add X(2), Y(2), 0, True, True, False, False, False, False
                .Add X(1), Y(1), 0, True, True, False, False, False, False
            End With
            GrChild.Closed = True
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            GrChild.Properties("BrushStyle") = "Solid"
            GrChild.Properties("BrushColor") = BColor
            Set GrChild = Gr.Graphics.Add(gkGraphic)
                      GrChild.Cosmetic = True
            With GrChild.Vertices
                .Add X(9), Y(9), 0, True, True, False, False, False, False
                .Add X(11), Y(11), 0, True, True, False, False, False, False
                .Add X(10), Y(10), 0, False, True, False, False, False, False
                .Add X(12), Y(12), 0, True, False, False, False, False, False
            End With
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
           '14
           Set GrChild = Gr.Graphics.AddArcTriplePoint(X(3), Y(3), 0#, X(13), Y(13), 0#, X(9), Y(9), 0#)
                      GrChild.Cosmetic = True
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
           '15
           Set GrChild = Gr.Graphics.AddArcTriplePoint(X(9), Y(9), 0#, X(17), Y(17), 0#, X(10), Y(10), 0#)
                      GrChild.Cosmetic = True
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
           '16
           Set GrChild = Gr.Graphics.AddArcTriplePoint(X(10), Y(10), 0#, X(14), Y(14), 0#, X(4), Y(4), 0#)
                      GrChild.Cosmetic = True
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
                      
           '14
           Set GrChild = Gr.Graphics.AddArcTriplePoint(X(5), Y(5), 0#, X(15), Y(15), 0#, X(11), Y(11), 0#)
                      GrChild.Cosmetic = True
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
           '15
           Set GrChild = Gr.Graphics.AddArcTriplePoint(X(11), Y(11), 0#, X(18), Y(18), 0#, X(12), Y(12), 0#)
                      GrChild.Cosmetic = True
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
           '16
           Set GrChild = Gr.Graphics.AddArcTriplePoint(X(12), Y(12), 0#, X(16), Y(16), 0#, X(6), Y(6), 0#)
                      GrChild.Cosmetic = True
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
    'Elliptical Arc
            
            Set GrChild = Gr.Application.ActiveDrawing.Graphics.AddArcRotatedElliptical((X(7) + X(8)) / 2, (Y(7) + Y(8)) / 2, 0#, X(19), Y(19), 0#, X(7), Y(7), 0#, -Pi / 2, Pi / 2)
            'Set GrChild = Gr.Graphics.AddArcRotatedElliptical((X(7) + X(8)) / 2, (Y(7) + Y(8)) / 2, 0#, X(19), Y(19), 0#, X(7), Y(7), 0#, -Pi / 2, Pi / 2)
                      'GrChild.Cosmetic = True
Dim GrHatch As Graphic
            Set GrHatch = GrChild.Graphics.AddHatch
                      GrHatch.Cosmetic = True
            GrHatch.Properties("BrushStyle") = "Solid"
            GrHatch.Properties("BrushColor") = BColor
            Gr.Application.ActiveDrawing.Graphics.Remove GrHatch.Index
            Gr.Graphics.AddGraphic GrHatch
            GrChild.Delete
            
            Set GrChild = Gr.Graphics.AddArcRotatedElliptical((X(7) + X(8)) / 2, (Y(7) + Y(8)) / 2, 0#, X(19), Y(19), 0#, X(7), Y(7), 0#, -Pi / 2, Pi / 2)
                      GrChild.Cosmetic = True
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            Set GrChild = Gr.Graphics.Add(gkGraphic)
                      GrChild.Cosmetic = True
            With GrChild.Vertices
                .Add X(7), Y(7), 0, True, True, False, False, False, False
                .Add X(8), Y(8), 0, True, True, False, False, False, False
            End With
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            
        End If

'-------------------------------------------------------------
' View Top
        If ViewN = "Top" Then
            Set GrChild = Gr.Graphics.Add(gkGraphic)
                      GrChild.Cosmetic = True
            With GrChild.Vertices
                For i = 0 To 6
                    x0(i) = D / 2 * Cos(Pi / 3 * i)
                    y0(i) = D / 2 * Sin(Pi / 3 * i)
                    X(i) = X00 + x0(i) * Calp - y0(i) * Salp
                    Y(i) = Y00 + x0(i) * Salp + y0(i) * Calp
                   .Add X(i), Y(i), 0, True, True, False, False, False, False
                Next i
            End With
            GrChild.Closed = True
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
             GrChild.Properties("BrushStyle") = "Solid"
             GrChild.Properties("BrushColor") = BColor
            Set GrChild = Gr.Graphics.AddCircleCenterAndPoint(X00, Y00, 0, X00 + D / 2 * Sin(Pi / 3), Y00, 0)
                      GrChild.Cosmetic = True
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            x0(7) = D / 2
            y0(7) = 0
            X(7) = X00 + x0(7) * Calp - y0(7) * Salp
            Y(7) = Y00 + x0(7) * Salp + y0(7) * Calp
            
           With Gr.Vertices
                .Item(1).X = X(7)
                .Item(1).Y = Y(7)
            End With
        End If
End Sub


Private Sub SquareNut(Gr As Graphic, dd As Double, LThread As Double)
Dim D#, H#, S#, K#, del#
        D = 2# * dd
        H = 0.9 * dd
        S = D * Cos(Pi / 4)
        K = 0.5 * (D - S) * Tan(Pi / 6)
        del = 0.15 * dd
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dim Salp#, Calp#, L#
Dim X00#, Y00#, X01#, Y01#
        With Gr.Vertices
            X00 = .Item(0).X
            Y00 = .Item(0).Y
            X01 = .Item(1).X
            Y01 = .Item(1).Y
            L = Sqr((X01 - X00) * (X01 - X00) + (Y01 - Y00) * (Y01 - Y00))
            Salp = (Y01 - Y00) / L
            Calp = (X01 - X00) / L
        End With
        If Abs(H - L) > 0.0001 Then
            X01 = X00 + H * Calp
            Y01 = Y00 + H * Salp
            With Gr.Vertices
                .Item(1).X = X01
                .Item(1).Y = Y01
                L = H
            End With
        End If
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Dim x0(22)
Dim y0(22)
Dim X(22)
Dim Y(22)
       
       x0(1) = 0#
       y0(1) = S / 2#
       
       x0(2) = x0(1)
       y0(2) = -y0(1)
       
       x0(3) = K
       y0(3) = D / 2#
       
       x0(4) = x0(3)
       y0(4) = -y0(3)
       
       x0(5) = H - K
       y0(5) = D / 2
       
       x0(6) = x0(5)
       y0(6) = -y0(5)
              
       x0(7) = H
       y0(7) = S / 2#
       
       x0(8) = x0(7)
       y0(8) = -y0(7)
       
       x0(9) = x0(3)
       y0(9) = 0#
       
       x0(10) = x0(5)
       y0(10) = 0#
       
       x0(11) = 0
       y0(11) = D / 4#
       
       x0(12) = x0(11)
       y0(12) = -y0(11)
       
       x0(13) = H
       y0(13) = D / 4
       
       x0(14) = x0(13)
       y0(14) = -y0(13)
       
' Thread
       x0(15) = H
       y0(15) = dd / 2
       
       x0(16) = x0(15)
       y0(16) = -y0(15)
       
       x0(17) = H + LThread - del
       y0(17) = dd / 2
       
       x0(18) = x0(17)
       y0(18) = -y0(17)
       
       x0(19) = H + LThread
       y0(19) = dd / 2 - del
       
       x0(20) = x0(19)
       y0(20) = -y0(19)
       
       x0(21) = H
       y0(21) = dd / 2 - del
       
       x0(22) = x0(21)
       y0(22) = -y0(21)
       
       
Dim i%
       For i = 1 To 22
          X(i) = X00 + x0(i) * Calp - y0(i) * Salp
          Y(i) = Y00 + x0(i) * Salp + y0(i) * Calp
       Next i
Dim GrChild As Graphic
            'Add child Graphics
        If ViewN = "Front" Then
            If LThread > 0.01 * dd Then
                Set GrChild = Gr.Graphics.Add(gkGraphic)
                          GrChild.Cosmetic = True
                With GrChild.Vertices
                    .Add X(15), Y(15), 0, True, True, False, False, False, False
                    .Add X(17), Y(17), 0, True, True, False, False, False, False
                    .Add X(19), Y(19), 0, True, True, False, False, False, False
                    .Add X(20), Y(20), 0, True, True, False, False, False, False
                    .Add X(18), Y(18), 0, True, True, False, False, False, False
                    .Add X(16), Y(16), 0, True, True, False, False, False, False
                    .Add X(15), Y(15), 0, True, True, False, False, False, False
                End With
                GrChild.Closed = True
                GrChild.Properties("PenWidth") = 0.02
                GrChild.Properties("PenColor") = PColor
                GrChild.Properties("BrushStyle") = "Solid"
                GrChild.Properties("BrushColor") = BColor
                Set GrChild = Gr.Graphics.Add(gkGraphic)
                          GrChild.Cosmetic = True
                With GrChild.Vertices
                    .Add X(17), Y(17), 0, False, True, False, False, False, False
                    .Add X(18), Y(18), 0, True, True, False, False, False, False
                End With
                GrChild.Properties("PenWidth") = 0.02
                GrChild.Properties("PenColor") = PColor
                Set GrChild = Gr.Graphics.Add(gkGraphic)
                          GrChild.Cosmetic = True
                With GrChild.Vertices
                    .Add X(21), Y(21), 0, True, True, False, False, False, False
                    .Add X(19), Y(19), 0, True, True, False, False, False, False
                    .Add X(22), Y(22), 0, False, True, False, False, False, False
                    .Add X(20), Y(20), 0, True, True, False, False, False, False
                End With
                GrChild.Properties("PenColor") = PColor
            End If
             Set GrChild = Gr.Graphics.Add(gkGraphic)
                       GrChild.Cosmetic = True
             With GrChild.Vertices
                 .Add X(1), Y(1), 0, True, True, False, False, False, False
                 .Add X(3), Y(3), 0, True, True, False, False, False, False
                 .Add X(5), Y(5), 0, True, True, False, False, False, False
                 .Add X(7), Y(7), 0, True, True, False, False, False, False
                 .Add X(8), Y(8), 0, True, True, False, False, False, False
                 .Add X(6), Y(6), 0, True, True, False, False, False, False
                 .Add X(4), Y(4), 0, True, True, False, False, False, False
                 .Add X(2), Y(2), 0, True, True, False, False, False, False
                 .Add X(1), Y(1), 0, True, True, False, False, False, False
             End With
             GrChild.Closed = True
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            GrChild.Properties("BrushStyle") = "Solid"
             GrChild.Properties("BrushColor") = BColor
             Set GrChild = Gr.Graphics.Add(gkGraphic)
                       GrChild.Cosmetic = True
             With GrChild.Vertices
                 .Add X(9), Y(9), 0, True, True, False, False, False, False
                 .Add X(10), Y(10), 0, True, True, False, False, False, False
             End With
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            '14
            Set GrChild = Gr.Graphics.AddArcTriplePoint(X(3), Y(3), 0#, X(11), Y(11), 0#, X(9), Y(9), 0#)
                       GrChild.Cosmetic = True
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            '15
            Set GrChild = Gr.Graphics.AddArcTriplePoint(X(9), Y(9), 0#, X(12), Y(12), 0#, X(4), Y(4), 0#)
                       GrChild.Cosmetic = True
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            '16
            Set GrChild = Gr.Graphics.AddArcTriplePoint(X(5), Y(5), 0#, X(13), Y(13), 0#, X(10), Y(10), 0#)
                       GrChild.Cosmetic = True
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
                       
            '14
            Set GrChild = Gr.Graphics.AddArcTriplePoint(X(10), Y(10), 0#, X(14), Y(14), 0#, X(6), Y(6), 0#)
                       GrChild.Cosmetic = True
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            '15
        End If
 '-------------------------------------------------------------
        If ViewN = "Top" Then
' View Top
            Set GrChild = Gr.Graphics.Add(gkGraphic)
                      GrChild.Cosmetic = True
            With GrChild.Vertices
                For i = 0 To 4
                    x0(i) = D / 2 * Cos(Pi / 2 * i)
                    y0(i) = D / 2 * Sin(Pi / 2 * i)
                    X(i) = X00 + x0(i) * Calp - y0(i) * Salp
                    Y(i) = Y00 + x0(i) * Salp + y0(i) * Calp
                   .Add X(i), Y(i), 0, True, True, False, False, False, False
                Next i
            End With
             GrChild.Closed = True
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
             GrChild.Properties("BrushStyle") = "Solid"
             GrChild.Properties("BrushColor") = BColor
            Set GrChild = Gr.Graphics.AddCircleCenterAndPoint(X00, Y00, 0, X00 + D / 2 * Sin(Pi / 4), Y00, 0)
                      GrChild.Cosmetic = True
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
             Set GrChild = Gr.Graphics.AddCircleCenterAndPoint(X00, Y00, 0, X00 + dd / 2, Y00, 0)
                      GrChild.Cosmetic = True
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            Set GrChild = Gr.Graphics.AddCircleCenterAndPoint(X00, Y00, 0, X00 + dd / 2 - del, Y00, 0)
                      GrChild.Cosmetic = True
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            x0(5) = D / 2
            y0(5) = 0
            X(5) = X00 + x0(5) * Calp - y0(5) * Salp
            Y(5) = Y00 + x0(5) * Salp + y0(5) * Calp
            
           With Gr.Vertices
                .Item(1).X = X(5)
                .Item(1).Y = Y(5)
            End With
        End If
End Sub

Private Sub HexFlangeNut(Gr As Graphic, dd As Double, LThread As Double)
Dim D#, Dw#, C#, K#, K1#, E#, Di#, del#
        D = 1.7 * dd
        Dw = 1.96 * dd
        C = 0.15 * dd
        K = 1# * dd
        K1 = 0.43 * dd
        E = (K - K1) * 0.85
        Di = D * Sin(Pi / 3#)
        del = 0.15 * dd
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dim Salp#, Calp#, L#
Dim X00#, Y00#, X01#, Y01#
        With Gr.Vertices
            X00 = .Item(0).X
            Y00 = .Item(0).Y
            X01 = .Item(1).X
            Y01 = .Item(1).Y
            L = Sqr((X01 - X00) * (X01 - X00) + (Y01 - Y00) * (Y01 - Y00))
            Salp = (Y01 - Y00) / L
            Calp = (X01 - X00) / L
        End With
        If Abs(K - L) > 0.0001 Then
            X01 = X00 + K * Calp
            Y01 = Y00 + K * Salp
            With Gr.Vertices
                .Item(1).X = X01
                .Item(1).Y = Y01
                L = K
            End With
        End If
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Dim x0(25)
Dim y0(25)
Dim X(25)
Dim Y(25)
       
       x0(1) = 0#
       y0(1) = Dw / 2#
       
       x0(2) = x0(1)
       y0(2) = -y0(1)
       
       x0(3) = C
       y0(3) = Dw / 2#
       
       x0(4) = x0(3)
       y0(4) = -y0(3)
       
       x0(5) = K1
       y0(5) = D / 2
       
       x0(6) = x0(5)
       y0(6) = -y0(5)
              
       x0(7) = K1 + E
       y0(7) = D / 2#
       
       x0(8) = x0(7)
       y0(8) = -y0(7)
       
       x0(9) = K
       y0(9) = Di / 2
       
       x0(10) = x0(9)
       y0(10) = -y0(9)
       
       x0(11) = K1
       y0(11) = D / 4#
       
       x0(12) = x0(11)
       y0(12) = -y0(11)
       
       x0(13) = x0(7)
       y0(13) = y0(11)
       
       x0(14) = x0(13)
       y0(14) = -y0(13)
       
       x0(15) = K
       y0(15) = 3# * D / 8#
       
       x0(16) = x0(15)
       y0(16) = -y0(15)
       
       x0(17) = K
       y0(17) = 0#
       
' Thread
       x0(18) = K
       y0(18) = dd / 2
       
       x0(19) = x0(18)
       y0(19) = -y0(18)
       
       x0(20) = K + LThread - del
       y0(20) = dd / 2
       
       x0(21) = x0(20)
       y0(21) = -y0(20)
       
       x0(22) = K + LThread
       y0(22) = dd / 2 - del
       
       x0(23) = x0(22)
       y0(23) = -y0(22)
       
       x0(24) = K
       y0(24) = dd / 2 - del
       
       x0(25) = x0(24)
       y0(25) = -y0(24)
       
       
Dim i%
       For i = 1 To 25
          X(i) = X00 + x0(i) * Calp - y0(i) * Salp
          Y(i) = Y00 + x0(i) * Salp + y0(i) * Calp
       Next i
Dim GrChild As Graphic
            'Add child Graphics
        If ViewN = "Front" Then
            If LThread > 0.01 * dd Then
                Set GrChild = Gr.Graphics.Add(gkGraphic)
                          GrChild.Cosmetic = True
                With GrChild.Vertices
                    .Add X(18), Y(18), 0, True, True, False, False, False, False
                    .Add X(20), Y(20), 0, True, True, False, False, False, False
                    .Add X(22), Y(22), 0, True, True, False, False, False, False
                    .Add X(23), Y(23), 0, True, True, False, False, False, False
                    .Add X(21), Y(21), 0, True, True, False, False, False, False
                    .Add X(19), Y(19), 0, True, True, False, False, False, False
                    .Add X(18), Y(18), 0, True, True, False, False, False, False
                End With
                GrChild.Closed = True
                GrChild.Properties("PenWidth") = 0.02
                GrChild.Properties("PenColor") = PColor
                GrChild.Properties("BrushStyle") = "Solid"
                GrChild.Properties("BrushColor") = BColor
                Set GrChild = Gr.Graphics.Add(gkGraphic)
                          GrChild.Cosmetic = True
                With GrChild.Vertices
                    .Add X(20), Y(20), 0, False, True, False, False, False, False
                    .Add X(21), Y(21), 0, True, True, False, False, False, False
                End With
                GrChild.Properties("PenWidth") = 0.02
                GrChild.Properties("PenColor") = PColor
                Set GrChild = Gr.Graphics.Add(gkGraphic)
                          GrChild.Cosmetic = True
                With GrChild.Vertices
                    .Add X(24), Y(24), 0, True, True, False, False, False, False
                    .Add X(22), Y(22), 0, True, True, False, False, False, False
                    .Add X(25), Y(25), 0, False, True, False, False, False, False
                    .Add X(23), Y(23), 0, True, True, False, False, False, False
                End With
                GrChild.Properties("PenColor") = PColor
            End If
             Set GrChild = Gr.Graphics.Add(gkGraphic)
                       GrChild.Cosmetic = True
             With GrChild.Vertices
                 .Add X(1), Y(1), 0, True, True, False, False, False, False
                 .Add X(3), Y(3), 0, True, True, False, False, False, False
                 .Add X(5), Y(5), 0, True, True, False, False, False, False
                 .Add X(7), Y(7), 0, True, True, False, False, False, False
                 .Add X(9), Y(9), 0, True, True, False, False, False, False
                 .Add X(10), Y(10), 0, True, True, False, False, False, False
                 .Add X(8), Y(8), 0, True, True, False, False, False, False
                 .Add X(6), Y(6), 0, True, True, False, False, False, False
                 .Add X(4), Y(4), 0, True, True, False, False, False, False
                 .Add X(2), Y(2), 0, True, True, False, False, False, False
                 .Add X(1), Y(1), 0, True, True, False, False, False, False
             End With
             GrChild.Closed = True
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
             GrChild.Properties("BrushStyle") = "Solid"
             GrChild.Properties("BrushColor") = BColor
             Set GrChild = Gr.Graphics.Add(gkGraphic)
                       GrChild.Cosmetic = True
             With GrChild.Vertices
                 .Add X(3), Y(3), 0, True, True, False, False, False, False
                 .Add X(4), Y(4), 0, True, True, False, False, False, False
                 .Add X(5), Y(5), 0, False, True, False, False, False, False
                 .Add X(6), Y(6), 0, True, True, False, False, False, False
                 .Add X(11), Y(11), 0, False, True, False, False, False, False
                 .Add X(13), Y(13), 0, True, True, False, False, False, False
                 .Add X(12), Y(12), 0, False, True, False, False, False, False
                 .Add X(14), Y(14), 0, True, True, False, False, False, False
             End With
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            '14
            Set GrChild = Gr.Graphics.AddArcTriplePoint(X(7), Y(7), 0#, X(15), Y(15), 0#, X(13), Y(13), 0#)
                       GrChild.Cosmetic = True
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            '15
            Set GrChild = Gr.Graphics.AddArcTriplePoint(X(8), Y(8), 0#, X(16), Y(16), 0#, X(14), Y(14), 0#)
                       GrChild.Cosmetic = True
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            '16
            Set GrChild = Gr.Graphics.AddArcTriplePoint(X(13), Y(13), 0#, X(17), Y(17), 0#, X(14), Y(14), 0#)
                       GrChild.Cosmetic = True
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
        End If
'-------------------------------------------------------------
' View Top
        If ViewN = "Top" Then
            Set GrChild = Gr.Graphics.AddCircleCenterAndPoint(X00, Y00, 0, X00 + Dw / 2, Y00, 0)
                      GrChild.Cosmetic = True
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
             GrChild.Properties("BrushStyle") = "Solid"
             GrChild.Properties("BrushColor") = BColor
            Set GrChild = Gr.Graphics.Add(gkGraphic)
                      GrChild.Cosmetic = True
            With GrChild.Vertices
                For i = 0 To 6
                    x0(i) = D / 2 * Cos(Pi / 3 * i)
                    y0(i) = D / 2 * Sin(Pi / 3 * i)
                    X(i) = X00 + x0(i) * Calp - y0(i) * Salp
                    Y(i) = Y00 + x0(i) * Salp + y0(i) * Calp
                   .Add X(i), Y(i), 0, True, True, False, False, False, False
                Next i
            End With
             GrChild.Closed = True
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            Set GrChild = Gr.Graphics.AddCircleCenterAndPoint(X00, Y00, 0, X00 + D / 2 * Sin(Pi / 3), Y00, 0)
                      GrChild.Cosmetic = True
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
             Set GrChild = Gr.Graphics.AddCircleCenterAndPoint(X00, Y00, 0, X00 + dd / 2, Y00, 0)
                      GrChild.Cosmetic = True
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            Set GrChild = Gr.Graphics.AddCircleCenterAndPoint(X00, Y00, 0, X00 + dd / 2 - del, Y00, 0)
                      GrChild.Cosmetic = True
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            x0(7) = D / 2
            y0(7) = 0
            X(7) = X00 + x0(7) * Calp - y0(7) * Salp
            Y(7) = Y00 + x0(7) * Salp + y0(7) * Calp
            
           With Gr.Vertices
                .Item(1).X = X(7)
                .Item(1).Y = Y(7)
            End With
        End If
End Sub

Private Sub HexSlottedNut(Gr As Graphic, dd As Double, LThread As Double)
Dim D#, H#, S#, K#, J#, H1#, del#
        D = 1.84 * dd
        H = 1# * dd
        S = D * Cos(Pi / 6)
        K = D / 2 * (1 - Cos(Pi / 6)) * Tan(Pi / 6)
        J = 0.3 * dd
        H1 = 0.3 * dd
        del = 0.15 * dd
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dim Salp#, Calp#, L#
Dim X00#, Y00#, X01#, Y01#
        With Gr.Vertices
            X00 = .Item(0).X
            Y00 = .Item(0).Y
            X01 = .Item(1).X
            Y01 = .Item(1).Y
            L = Sqr((X01 - X00) * (X01 - X00) + (Y01 - Y00) * (Y01 - Y00))
            Salp = (Y01 - Y00) / L
            Calp = (X01 - X00) / L
        End With
        If Abs(H - L) > 0.0001 Then
            X01 = X00 + H * Calp
            Y01 = Y00 + H * Salp
            With Gr.Vertices
                .Item(1).X = X01
                .Item(1).Y = Y01
                L = H
            End With
        End If
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Dim x0(41)
Dim y0(41)
Dim X(41)
Dim Y(41)
       
       x0(1) = 0#
       y0(1) = S / 2#
       
       x0(2) = x0(1)
       y0(2) = -y0(1)
       
       x0(3) = K
       y0(3) = D / 2#
       
       x0(4) = x0(3)
       y0(4) = -y0(3)
       
       x0(5) = H - K
       y0(5) = D / 2
       
       x0(6) = x0(5)
       y0(6) = -y0(5)
              
       x0(7) = H
       y0(7) = S / 2#
       
       x0(8) = x0(7)
       y0(8) = -y0(7)
       
       x0(9) = x0(3)
       y0(9) = D / 4
       
       x0(10) = x0(9)
       y0(10) = -y0(9)
       
       x0(11) = x0(5)
       y0(11) = D / 4#
       
       x0(12) = x0(11)
       y0(12) = -y0(11)
       
       x0(13) = 0#
       y0(13) = 3 * D / 8
       
       x0(14) = x0(13)
       y0(14) = -y0(13)
       
       x0(15) = H
       y0(15) = 3 * D / 8
       
       x0(16) = x0(15)
       y0(16) = -y0(15)
       
       x0(17) = 0
       y0(17) = 0
       
       x0(18) = H
       y0(18) = 0#
'#########################################################
       x0(19) = H
       y0(19) = y0(15) + J / 4
       x0(20) = H
       y0(20) = y0(15) - J / 4

       x0(21) = H - H1
       y0(21) = y0(19)
       x0(22) = x0(21)
       y0(22) = y0(20)

       x0(23) = H - H1 - J / 4
       y0(23) = y0(15)
'--------------------------------------------------------
       x0(24) = H
       y0(24) = y0(16) + J / 4
       x0(25) = H
       y0(25) = y0(16) - J / 4

       x0(26) = H - H1
       y0(26) = y0(24)
       x0(27) = x0(26)
       y0(27) = y0(25)

       x0(28) = x0(23)
       y0(28) = y0(16)
       
'--------------------------------------------------------
       x0(29) = H
       y0(29) = J / 2
       x0(30) = H
       y0(30) = -J / 2

       x0(31) = x0(21) + J / 4
       y0(31) = y0(29)
       x0(32) = x0(21) + J / 4
       y0(32) = y0(30)

       x0(33) = x0(23)
       y0(33) = 0#
       
' Thread
       x0(34) = H
       y0(34) = dd / 2
       
       x0(35) = x0(34)
       y0(35) = -y0(34)
       
       x0(36) = H + LThread - del
       y0(36) = dd / 2
       
       x0(37) = x0(36)
       y0(37) = -y0(36)
       
       x0(38) = H + LThread
       y0(38) = dd / 2 - del
       
       x0(39) = x0(38)
       y0(39) = -y0(38)
       
       x0(40) = H
       y0(40) = dd / 2 - del
       
       x0(41) = x0(40)
       y0(41) = -y0(40)
       
       
Dim i%
       For i = 1 To 41
          X(i) = X00 + x0(i) * Calp - y0(i) * Salp
          Y(i) = Y00 + x0(i) * Salp + y0(i) * Calp
       Next i
Dim GrChild As Graphic
            'Add child Graphics
        If ViewN = "Front" Then
            If LThread > 0.01 * dd Then
                Set GrChild = Gr.Graphics.Add(gkGraphic)
                          GrChild.Cosmetic = True
                With GrChild.Vertices
                    .Add X(34), Y(34), 0, True, True, False, False, False, False
                    .Add X(36), Y(36), 0, True, True, False, False, False, False
                    .Add X(38), Y(38), 0, True, True, False, False, False, False
                    .Add X(39), Y(39), 0, True, True, False, False, False, False
                    .Add X(37), Y(37), 0, True, True, False, False, False, False
                    .Add X(35), Y(35), 0, True, True, False, False, False, False
                    .Add X(34), Y(34), 0, True, True, False, False, False, False
                End With
                GrChild.Closed = True
                GrChild.Properties("PenWidth") = 0.02
                GrChild.Properties("PenColor") = PColor
                GrChild.Properties("BrushStyle") = "Solid"
                 GrChild.Properties("BrushColor") = BColor
               Set GrChild = Gr.Graphics.Add(gkGraphic)
                          GrChild.Cosmetic = True
                With GrChild.Vertices
                    .Add X(36), Y(36), 0, False, True, False, False, False, False
                    .Add X(37), Y(37), 0, True, True, False, False, False, False
                End With
                GrChild.Properties("PenWidth") = 0.02
                GrChild.Properties("PenColor") = PColor
                Set GrChild = Gr.Graphics.Add(gkGraphic)
                          GrChild.Cosmetic = True
                With GrChild.Vertices
                    .Add X(40), Y(40), 0, True, True, False, False, False, False
                    .Add X(38), Y(38), 0, True, True, False, False, False, False
                    .Add X(41), Y(41), 0, False, True, False, False, False, False
                    .Add X(39), Y(39), 0, True, True, False, False, False, False
                End With
                GrChild.Properties("PenColor") = PColor
            End If
            Set GrChild = Gr.Graphics.Add(gkGraphic)
                      GrChild.Cosmetic = True
            With GrChild.Vertices
                .Add X(1), Y(1), 0, True, True, False, False, False, False
                .Add X(3), Y(3), 0, True, True, False, False, False, False
                .Add X(5), Y(5), 0, True, True, False, False, False, False
                .Add X(7), Y(7), 0, True, True, False, False, False, False
                .Add X(8), Y(8), 0, True, True, False, False, False, False
                .Add X(6), Y(6), 0, True, True, False, False, False, False
                .Add X(4), Y(4), 0, True, True, False, False, False, False
                .Add X(2), Y(2), 0, True, True, False, False, False, False
                .Add X(1), Y(1), 0, True, True, False, False, False, False
            End With
            GrChild.Closed = True
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            GrChild.Properties("BrushStyle") = "Solid"
            GrChild.Properties("BrushColor") = BColor
            Set GrChild = Gr.Graphics.Add(gkGraphic)
                      GrChild.Cosmetic = True
            With GrChild.Vertices
                .Add X(9), Y(9), 0, True, True, False, False, False, False
                .Add X(11), Y(11), 0, True, True, False, False, False, False
                .Add X(10), Y(10), 0, False, True, False, False, False, False
                .Add X(12), Y(12), 0, True, True, False, False, False, False
            End With
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
           '14
           Set GrChild = Gr.Graphics.AddArcTriplePoint(X(3), Y(3), 0#, X(13), Y(13), 0#, X(9), Y(9), 0#)
                      GrChild.Cosmetic = True
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
           '15
           Set GrChild = Gr.Graphics.AddArcTriplePoint(X(9), Y(9), 0#, X(17), Y(17), 0#, X(10), Y(10), 0#)
                      GrChild.Cosmetic = True
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
           '16
           Set GrChild = Gr.Graphics.AddArcTriplePoint(X(10), Y(10), 0#, X(14), Y(14), 0#, X(4), Y(4), 0#)
                      GrChild.Cosmetic = True
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
                      
           '14
           Set GrChild = Gr.Graphics.AddArcTriplePoint(X(5), Y(5), 0#, X(15), Y(15), 0#, X(11), Y(11), 0#)
                      GrChild.Cosmetic = True
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
           '15
           Set GrChild = Gr.Graphics.AddArcTriplePoint(X(11), Y(11), 0#, X(18), Y(18), 0#, X(12), Y(12), 0#)
                      GrChild.Cosmetic = True
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
           '16
           Set GrChild = Gr.Graphics.AddArcTriplePoint(X(12), Y(12), 0#, X(16), Y(16), 0#, X(6), Y(6), 0#)
                      GrChild.Cosmetic = True
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
    '-------------------------------------------------------------
            Set GrChild = Gr.Graphics.Add(gkGraphic)
                      GrChild.Cosmetic = True
             With GrChild.Vertices
                .Add X(19), Y(19), 0, True, True, False, False, False, False
                .Add X(21), Y(21), 0, True, True, False, False, False, False
            End With
            GrChild.Properties("PenColor") = PColor
            GrChild.Properties("PenWidth") = 0.02
            Set GrChild = Gr.Graphics.Add(gkGraphic)
                      GrChild.Cosmetic = True
             With GrChild.Vertices
                .Add X(20), Y(20), 0, True, True, False, False, False, False
                .Add X(22), Y(22), 0, True, True, False, False, False, False
            End With
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
           Set GrChild = Gr.Graphics.AddArcTriplePoint(X(21), Y(21), 0#, X(23), Y(23), 0#, X(22), Y(22), 0#)
                      GrChild.Cosmetic = True
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
    '-------------------------------------------------------------
            Set GrChild = Gr.Graphics.Add(gkGraphic)
                      GrChild.Cosmetic = True
             With GrChild.Vertices
                .Add X(24), Y(24), 0, True, True, False, False, False, False
                .Add X(26), Y(26), 0, True, True, False, False, False, False
            End With
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            Set GrChild = Gr.Graphics.Add(gkGraphic)
                      GrChild.Cosmetic = True
             With GrChild.Vertices
                .Add X(25), Y(25), 0, True, True, False, False, False, False
                .Add X(27), Y(27), 0, True, True, False, False, False, False
            End With
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
           Set GrChild = Gr.Graphics.AddArcTriplePoint(X(26), Y(26), 0#, X(28), Y(28), 0#, X(27), Y(27), 0#)
                      GrChild.Cosmetic = True
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
    '-------------------------------------------------------------
            Set GrChild = Gr.Graphics.Add(gkGraphic)
                      GrChild.Cosmetic = True
             With GrChild.Vertices
                .Add X(29), Y(29), 0, True, True, False, False, False, False
                .Add X(31), Y(31), 0, True, True, False, False, False, False
            End With
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            Set GrChild = Gr.Graphics.Add(gkGraphic)
                      GrChild.Cosmetic = True
             With GrChild.Vertices
                .Add X(30), Y(30), 0, True, True, False, False, False, False
                .Add X(32), Y(32), 0, True, True, False, False, False, False
            End With
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
           Set GrChild = Gr.Graphics.AddArcTriplePoint(X(31), Y(31), 0#, X(33), Y(33), 0#, X(32), Y(32), 0#)
                      GrChild.Cosmetic = True
            GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
        End If
                
        If ViewN = "Top" Then
' View Top
            Set GrChild = Gr.Graphics.Add(gkGraphic)
                      GrChild.Cosmetic = True
            With GrChild.Vertices
                For i = 0 To 6
                    x0(i) = D / 2 * Cos(Pi / 3 * i)
                    y0(i) = D / 2 * Sin(Pi / 3 * i)
                    X(i) = X00 + x0(i) * Calp - y0(i) * Salp
                    Y(i) = Y00 + x0(i) * Salp + y0(i) * Calp
                   .Add X(i), Y(i), 0, True, True, False, False, False, False
                Next i
            End With
             GrChild.Closed = True
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
             GrChild.Properties("BrushStyle") = "Solid"
             GrChild.Properties("BrushColor") = BColor
             Set GrChild = Gr.Graphics.AddCircleCenterAndPoint(X00, Y00, 0, X00 + dd / 2, Y00, 0)
                      GrChild.Cosmetic = True
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            Set GrChild = Gr.Graphics.AddCircleCenterAndPoint(X00, Y00, 0, X00 + dd / 2 - del, Y00, 0)
                      GrChild.Cosmetic = True
             GrChild.Properties("PenWidth") = 0.02
            GrChild.Properties("PenColor") = PColor
            x0(7) = D / 2
            y0(7) = 0
            X(7) = X00 + x0(7) * Calp - y0(7) * Salp
            Y(7) = Y00 + x0(7) * Salp + y0(7) * Calp
            
           With Gr.Vertices
                .Item(1).X = X(7)
                .Item(1).Y = Y(7)
            End With
Dim x1#, y1#, x2#, y2#, x3#, y3#, x4#, y4#, x5#, y5#, x6#, y6#, x7#, y7#
            x1 = D / 2
            y1 = 0#
            x2 = x1 - D / 4 * Sin(Pi / 6)
            y2 = y1 + D / 4 * Sin(Pi / 3)
            x4 = x2 + J / 2 * Sin(Pi / 6)
            y4 = y2 - J / 2 * Sin(Pi / 3)
            x5 = x2 - J / 2 * Sin(Pi / 6)
            y5 = y2 + J / 2 * Sin(Pi / 3)
Dim L1#, hx#
            
            L1 = Sqr((x4 - x5) * (x4 - x5) + (y4 - y5) * (y4 - y5))
            hx = Sqr(dd * dd / 4 - L1 * L1 / 4)
            x3 = x2 - (D / 2 * Sin(Pi / 3) - hx) * Sin(Pi / 3)
            y3 = y2 - (D / 2 * Sin(Pi / 3) - hx) * Sin(Pi / 6)
            x6 = x3 + J / 2 * Sin(Pi / 6)
            y6 = y3 - J / 2 * Sin(Pi / 3)
            x7 = x3 - J / 2 * Sin(Pi / 6)
            y7 = y3 + J / 2 * Sin(Pi / 3)
Dim x41#, y41#, x51#, y51#, x61#, y61#, x71#, y71#
Dim x42#, y42#, x52#, y52#, x62#, y62#, x72#, y72#
Dim xc#, yc#, xc1#, yc1#, xc2#, yc2#, xc3#, yc3#
            For i = 0 To 5
                x41 = x4 * Cos(Pi / 3 * i) - y4 * Sin(Pi / 3 * i)
                y41 = x4 * Sin(Pi / 3 * i) + y4 * Cos(Pi / 3 * i)
                x51 = x5 * Cos(Pi / 3 * i) - y5 * Sin(Pi / 3 * i)
                y51 = x5 * Sin(Pi / 3 * i) + y5 * Cos(Pi / 3 * i)
                x61 = x6 * Cos(Pi / 3 * i) - y6 * Sin(Pi / 3 * i)
                y61 = x6 * Sin(Pi / 3 * i) + y6 * Cos(Pi / 3 * i)
                x71 = x7 * Cos(Pi / 3 * i) - y7 * Sin(Pi / 3 * i)
                y71 = x7 * Sin(Pi / 3 * i) + y7 * Cos(Pi / 3 * i)
                x42 = X00 + x41 * Calp - y41 * Salp
                y42 = Y00 + x41 * Salp + y41 * Calp
                x52 = X00 + x51 * Calp - y51 * Salp
                y52 = Y00 + x51 * Salp + y51 * Calp
                x62 = X00 + x61 * Calp - y61 * Salp
                y62 = Y00 + x61 * Salp + y61 * Calp
                x72 = X00 + x71 * Calp - y71 * Salp
                y72 = Y00 + x71 * Salp + y71 * Calp
                Set GrChild = Gr.Graphics.Add(gkGraphic)
                          GrChild.Cosmetic = True
                With GrChild.Vertices
                   .Add x42, y42, 0, True, True, False, False, False, False
                   .Add x62, y62, 0, True, True, False, False, False, False
                   .Add x52, y52, 0, False, True, False, False, False, False
                   .Add x72, y72, 0, True, True, False, False, False, False
                End With
                GrChild.Properties("PenWidth") = 0.02
                GrChild.Properties("PenColor") = PColor
               xc1 = x42
                yc1 = y42
                xc = D / 2 * Sin(Pi / 3) * Cos(Pi / 3 * i)
                yc = D / 2 * Sin(Pi / 3) * Sin(Pi / 3 * i)
                xc2 = X00 + xc * Calp - yc * Salp
                yc2 = Y00 + xc * Salp + yc * Calp
                x41 = x4 * Cos(Pi / 3 * i) + y4 * Sin(Pi / 3 * i)
                y41 = x4 * Sin(Pi / 3 * i) - y4 * Cos(Pi / 3 * i)
                xc3 = X00 + x41 * Calp - y41 * Salp
                yc3 = Y00 + x41 * Salp + y41 * Calp
                Set GrChild = Gr.Graphics.AddArcTriplePoint(xc1, yc1, 0, xc2, yc2, 0, xc3, yc3, 0)
                          GrChild.Cosmetic = True
                GrChild.Properties("PenWidth") = 0.02
                GrChild.Properties("PenColor") = PColor
            Next i
        End If
End Sub

